<?php

namespace App\Models\Admin\Menus;

class MenuButtonsModel extends BaseMenuModel
{
    protected $table = 'menu_buttons';

    /**
     * @param array $menuIds
     * @param array $fields
     * @return array
     */
    public function getItemsByMenuIds(array $menuIds, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
            ->whereIn('menu_id', $menuIds)
            ->where('deleted', self::DELETED_NO)
            ->get()
            ->toArray();
    }

    /**
     * 根据菜单id将数据标记为删除状态
     *
     * @param int $menuId 菜单id
     * @return mixed
     */
    public function deleteItemByMenuId(int $menuId)
    {
        return $this->where('menu_id', $menuId)
            ->where('deleted', self::DELETED_NO)
            ->update([
                'deleted' => self::DELETED_YES,
            ]);
    }
}
